package cn.itsource.user.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.user.dto.LoginDto;
import cn.itsource.user.service.ILoginInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILoginInfoService loginInfoService;
    @PostMapping("/account")
    public AjaxResult loginAccount(@RequestBody LoginDto loginDto){

        try {
            //不仅要校验，还有返回值，所以在里面直接封装AjaxResult更好
           return loginInfoService.loginAccount(loginDto);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统错误！"+e.getMessage());
        }
    }

    @PostMapping("/wechat")
    public AjaxResult loginWechat(@RequestBody Map<String,String> params){

        try {
            return  loginInfoService.loginWechat(params);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统错误！"+e.getMessage());
        }
    }

    @PostMapping("/binder/wechat")
    public AjaxResult binderWechat(@RequestBody Map<String,String> params){

        try {
            return  loginInfoService.binderWechat(params);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统错误！"+e.getMessage());
        }
    }
}
